package com.zusmart.base.scanner.support;

import java.util.jar.JarEntry;

import com.zusmart.base.scanner.ScannerResult;

public abstract class AbstractScannerResult implements ScannerResult {

	private final String name;
	private final String path;

	protected AbstractScannerResult(String name, String path) {
		this.name = name;
		this.path = path;
	}

	@Override
	public String getName() {
		return this.name;
	}

	@Override
	public String getPath() {
		return this.path;
	}

	@Override
	public String toString() {
		return String.format("[%s-%s] %s", this.isFromDirFile() ? "DIR" : "JAR", this.getName(), this.getPath());
	}

	protected static String getFileName(JarEntry jarEntry) {
		String entryName = jarEntry.getName();
		int index = entryName.lastIndexOf("/");
		if (index >= 0) {
			entryName = entryName.substring(index + 1);
		}
		return entryName;
	}

}